﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Text.Editor;
using System.Windows;
using System.Windows.Input;

namespace VsSpeakerCompanion.UI
{
    internal class UIService : IUIService
    {
        IVisualStudioService visualStudioService;

        /// <summary>
        /// See <see cref="IUIService"/> for more information
        /// </summary>
        /// <param name="visualStudioService"></param>
        public UIService(IVisualStudioService visualStudioService)
        {
            this.visualStudioService = visualStudioService;
        }

        /// <summary>
        /// See <see cref="IUIService"/> for more information
        /// </summary>
        /// <param name="message"></param>
        public void ShowMessage(string message)
        {
            MessageBox.Show(message, "Demo Dashboard Message");
        }

        /// <summary>
        /// See <see cref="IUIService"/> for more information
        /// </summary>
        /// <param name="errorMessage"></param>
        public void ShowError(string errorMessage)
        {
            this.ShowMessage(errorMessage);
        }

        /// <summary>
        /// See <see cref="IUIService"/> for more information
        /// </summary>
        /// <param name="exception"></param>
        public void ShowError(Exception exception)
        {
            this.ShowMessage(exception.Message);
        }

        /// <summary>
        /// See <see cref="IUIService"/> for more information
        /// </summary>
        /// <param name="window"></param>
        public void ShowDialog(Window window)
        {
            // Check if we could use the VS IUIService to show the WPF window as dialog
            window.ShowDialog();
        }

        /// <summary>
        /// See <see cref="IUIService"/> for more information
        /// </summary>
        /// <param name="operation"></param>
        /// <returns></returns>
        public bool ExecuteOperation(Action operation)
        {
            try
            {
                Mouse.OverrideCursor = Cursors.Wait;
                operation();
                return true;
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                ShowError(ex);
                return false;
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }
    }
}